package java44th.group.service.wx.brand;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java44th.group.bean.common.BasePageInfo;
import java44th.group.bean.common.CommonData;
import java44th.group.bean.po.MarketBrand;
import java44th.group.bean.po.MarketBrandExample;
import java44th.group.bean.wx.vo.brand.ListVo;
import java44th.group.mapper.MarketBrandMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName project-second
 * @Descriptiom TODO
 * @Aurhor: 蔡文强
 * @Since: 2022/10/15 0:08
 */
@Service
public class WxBrandServiceImpl implements WxBrandService {

    @Autowired
    MarketBrandMapper marketBrandMapper;

    @Override
    public CommonData<ListVo> queryBrandList(BasePageInfo basePageInfo) {

        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());

        MarketBrandExample example = new MarketBrandExample();
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(example);

        PageInfo<MarketBrand> pageInfo = new PageInfo(marketBrands);

        List<ListVo> listVos = new ArrayList<>();
        for (MarketBrand marketBrand : marketBrands) {
            ListVo listVo = new ListVo(marketBrand.getFloorPrice().doubleValue(),marketBrand.getPicUrl(),
                    marketBrand.getName(),marketBrand.getId(),marketBrand.getDesc());
            listVos.add(listVo);
        }


        return CommonData.dataWithList(pageInfo, listVos);
    }

    @Override
    public MarketBrand queryBrandInfoById(Integer id) {

        MarketBrandExample example = new MarketBrandExample();
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(example);

        return marketBrands.get(0);
    }
}
